<?
	$url=$_SERVER['HTTP_HOST'].$_SERVER['QUERY_STRING']; 
	if (eregi("contact.php",$url)) {	
		die("&nbsp;");
	}
	//check_gpc();
	$template_products_body="template/product_list.tpl";
	$template_contactList="template/contact_list.tpl";
	$template_memContact="template/memContact.tpl";
	$template_guestContact="template/guestContact.tpl";
	
	$base_url 	= 'index.php';
	
	$url= substr($url,strpos($url,".php"),strlen($url));
	$url=explode("/",$url);
	
	$mode=$url[2] ; 
	
	switch($mode){ 
		  case "delete":
			 deleteContact();
			 break;
		  case "send":
			  sendContact();
			  break;
		  case "gsend":
			  SendGuestContact();
			  break;
		  default:
			  viewcontact(); 
			  break; 
	} 
function SendGuestContact(){
	
	global $db,$template,$site_base_href;
	require_once("class/email.php");
	//Thu nhan bien tu form	
	$txtQuantity=isset($_POST["txtQuantity"]) ? htmlspecialchars($_POST["txtQuantity"]) : ' '; 
	$txtSubject=isset($_POST["txtSubject"]) ? htmlspecialchars($_POST["txtSubject"]) : ' '; 
	$txtMessage=isset($_POST["txtMessage"]) ? htmlspecialchars($_POST["txtMessage"]) : ' ';
	
	$txtFirsName=isset($_POST["txtFirsName"]) ? htmlspecialchars($_POST["txtFirsName"]) : ' '; 
	$txtLastName=isset($_POST["txtLastName"]) ? htmlspecialchars($_POST["txtLastName"]) : ' '; 
	$txtCompany=isset($_POST["txtCompany"]) ? htmlspecialchars($_POST["txtCompany"]) : ' ';
	
	$optContry=isset($_POST["optContry"]) ? intval($_POST["optContry"]) : 0;
	$txtAddress=isset($_POST["txtAddress"]) ? htmlspecialchars($_POST["txtAddress"]) : ' ';
	$txtEmail=isset($_POST["txtEmail"]) ? htmlspecialchars($_POST["txtEmail"]) : ' ';	
 
	$txtContrycode=isset($_POST["txtContrycode"]) ? htmlspecialchars($_POST["txtContrycode"]) : ' ';
	$txtAreacode=isset($_POST["txtAreacode"]) ? htmlspecialchars($_POST["txtAreacode"]) : ' ';
	$txtBussinessPhone=isset($_POST["txtBussinessPhone"]) ? htmlspecialchars($_POST["txtBussinessPhone"]) : ' ';
	$Phone=$txtContrycode." " .$txtAreacode." ".$txtBussinessPhone;
	
	$txtContrycodefax=isset($_POST["txtContrycodefax"]) ? htmlspecialchars($_POST["txtContrycodefax"]) : ' ';
	$txtAreacodefax=isset($_POST["txtAreacodefax"]) ? htmlspecialchars($_POST["txtAreacodefax"]) : ' ';
	$txtBussinessPhonefax=isset($_POST["txtBussinessPhonefax"]) ? htmlspecialchars($_POST["txtBussinessPhonefax"]) : ' ';
	$fax=$txtContrycodefax." ".$txtAreacodefax." ".$txtBussinessPhonefax;
	
	$contactID=isset($_POST["contactID"]) ? intval($_POST["contactID"]) : 0;
	$chkSes=isset($_POST["chkSes"]) ? intval($_POST["chkSes"]) : 0;

	// contact  doi voi giang hang
	if($chkSes){
		$ses_pro=$_SESSION["ses_pro1"];
    }else{
		$ses_pro=$_SESSION["ses_pro"];
	}
	if(is_array($ses_pro)){
		while (list($id,) = each($ses_pro)){
			$id	= intval($id);
			if ($id){
			$sql="select  mEmail,FirstName,vb_member.memID from vb_member inner join vb_memberprofile on vb_member.memID=vb_memberprofile.memID inner join vb_sell_lead on vb_sell_lead.memId=vb_member.memID where vb_sell_lead.lID=".$id;
			if(!$result=$db->sql_query($sql)){			 
			 	message_die("Couldn't run the sql query!","",__LINE__,__FILE__,$sql);
			}	
			$memid=$db->sql_fetchrow($result);	

			$sql="insert into vb_contact (FirstName,LastName,companyName,ContryID,address,email,bphone,bfax,lID,memID,subject,mess,quantity,datepost,proOrder) values ('$txtFirsName','$txtLastName','$txtCompany',$optContry,'$txtAddress','$txtEmail','$Phone','$fax',$id,".$memid['memID'].",'$txtSubject','$txtMessage','$txtQuantity','".date("Y-m-d")."','0')";
			
			if(!$result=$db->sql_query($sql)){			 
				 message_die($sql."Couldn't run the sql query!!","",__LINE__,__FILE__,$sql);
			}	
		
		 $filecontent='Dear '.$memid["FirstName"].',<br>
			You have a new message from a yellowpages.vn member. To view the message logon to the link below:<br>
			<a href="'.$site_base_href.'/userLog.php">'.$site_base_href.'/userLog.php</a><br><br>					
			Kind regards,<br>www.yellowpages.vn Team<br>';					
		 
			$mail= new email();			 
			$mail->to =$memid["mEmail"];
			$mail->toname =$memid["FirstName"];
			$mail->fromname ="VietBig";
			$mail->from = "support@yellowpages.vn";
			$mail->enable_html = true;				
			$mail->subject = "yellowpages.vn";
			$mail->body = $filecontent;		
			$mail->send();		
			}
		}
		
		unset($ses_pro);
		session_unregister("ses_pro1");
		session_unregister("ses_pro");
	}
	
	//contact doi voi san pham
	if($chkSes){
		$ses_pros=$_SESSION["ses_pros1"]; 
	}else{
		$ses_pros=$_SESSION["ses_pros"]; 
	}
	//Goi mail to khach hang
	if(is_array($ses_pros)){
		while (list($id,) = each($ses_pros)){
			$id	= intval($id); 
			if ($id){
			$sql="select mEmail,FirstName,vb_member.memID from vb_member inner join vb_memberprofile on vb_member.memID=vb_memberprofile.memID inner join vb_products on vb_products.memId=vb_member.memID where vb_products.proID=".$id;
			if(!$result=$db->sql_query($sql)){			 
			 	message_die("Couldn't run the sql query!!!3","",__LINE__,__FILE__,$sql);
			}	
			$memid=$db->sql_fetchrow($result);	
			$sql="insert into vb_contact (FirstName,LastName,companyName,ContryID,address,email,bphone,bfax,lID,memID,subject,mess,quantity,datepost,proOrder) values ('$txtFirsName','$txtLastName','$txtCompany',$optContry,'$txtAddress','$txtEmail','$Phone','$fax',$id,".$memid['memID'].",'$txtSubject','$txtMessage','$txtQuantity','".date("Y-m-d")."','1')";

			if(!$result=$db->sql_query($sql)){			 
				 message_die($sql."Couldn't run the sql query!!!4","",__LINE__,__FILE__,$sql);
			}	
		 $filecontent='Dear '.$memid["FirstName"].',<br>
			You have a new message from a YellowPages.vn member. To view the message logon to the link below:<br>
			<a href="'.$site_base_href.'/userLog.php">'.$site_base_href.'</a><br><br>					
			Kind regards,<br> www.yellowpages.vn Team<br><br><br><a href="javascript:window.close();" class="quote">Close</a>';					
	 
	 
		$mail= new email();			 
		$mail->to =$memid["mEmail"];
		$mail->toname =$memid["FirstName"];
		$mail->fromname ="VietBig";
		$mail->from = "support@yellowpages.vn";
		$mail->enable_html = true;				
		$mail->subject = "yellowpages.vn";
		$mail->body = $filecontent;		
		$mail->send();		
			}
		}
		unset($ses_pros);
		session_unregister("ses_pros1");
		session_unregister("ses_pros");
	}
	// contact toi khach hang
	if(!empty($contactID)){	
		$sql="insert into vb_contact (FirstName,LastName,companyName,ContryID,address,email,bphone,bfax,lID,memID,subject,mess,quantity,datepost,proOrder) values ('$txtFirsName','$txtLastName','$txtCompany',$optContry,'$txtAddress','$txtEmail','$Phone','$fax',0,$contactID,'$txtSubject','$txtMessage','$txtQuantity','".date("Y-m-d")."','3')";
		 
	if(!$result=$db->sql_query($sql)){			 
		 message_die("Couldn't run the sql query!!!5","",__LINE__,__FILE__,$sql);
	}	
		
		$sql="select  mEmail,FirstName from vb_member inner join vb_memberprofile on vb_member.memID=vb_memberprofile.memID  where vb_member.memID=".$contactID;
 
			if(!$result=$db->sql_query($sql)){			 
			 	message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
			}	
			$memid=$db->sql_fetchrow($result);	
		 $filecontent='Dear '.$memid["FirstName"].',<br>
			You have a new message from a yellowpages.vn member. To view the message logon to the link below:<br>
			<a href="'.$site_base_href.'/userLog.php">'.$site_base_href.'</a><br><br>					
			Kind regards,<br>www.yellowpages.vn Team<br><br><br><a href="javascript:window.close();" class="quote">Close</a>';					
	
		$mail= new email();			 
		$mail->to =$memid["mEmail"];
		$mail->toname =$memid["FirstName"];
		$mail->fromname ="YellowPages";
		$mail->from = "support@yellowpages.vn";
		$mail->enable_html = true;				
		$mail->subject = "YellowPages.vn";
		$mail->body = $filecontent;		
		$mail->send();		
		
	}	
	echo ' <table width="100%"  border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td height="300" valign="top" class="quote">	<div align="center" ><br>
			  <br>Thank you! Message Successfully Sent!<br>Thank you for contacting us. We will reply your inquiry as soon as possible.<br><br><br><br><a href="javascript:window.close();" class="quote">Close</a> </td>
		  </tr>
		</table>
		';
} 
function sendContact(){
	global $db,$template,$site_base_href;
	
	$txtQuantity=isset($_POST["txtQuantity"]) ? htmlspecialchars($_POST["txtQuantity"]) : ''; 
	$txtSubject=isset($_POST["txtSubject"]) ? htmlspecialchars($_POST["txtSubject"]) : ''; 
	$txtMessage=isset($_POST["txtMessage"]) ? htmlspecialchars($_POST["txtMessage"]) : '';
	$chkSes=isset($_POST["chkSes"]) ? intval($_POST["chkSes"]) : 0 ;
	$contactID=isset($_POST["contactID"]) ? intval($_POST["contactID"]) : 0;
	
	if($chkSes){
		$ses_pro=$_SESSION["ses_pro1"];
		$ses_pros=$_SESSION["ses_pros1"];
	}else{	
		$ses_pro=$_SESSION["ses_pro"];
		$ses_pros=$_SESSION["ses_pros"];
	}	
	
	require_once("class/email.php");		
		 
	if(!empty($contactID)){
		$sql='select s.memID,s.lID,p.FirstName,p.LastName,m.mEmail,p.CompanyName,p.Address,p.countryID,CONCAT(p.contrycode," ",p.areacode," ",BusinessPhone) as bphone,CONCAT(p.faxcontrycode," ",p.faxareacode," ",FaxNumber) as bfax from vb_sell_lead s inner join vb_member m on m.memID=s.memID inner join vb_memberprofile p on m.memID=p.memID where m.memID='.$contactID ." limit 1";
		if(!$result=$db->sql_query($sql)){			 
	 		 message_die("Couldn't run the sql query!!!1","",__LINE__,__FILE__,$sql);
		}	
		$cust_data=$db->sql_fetchrow($result);	
		$db->sql_freeresult($result);	
	
		$sql="insert into vb_contact(FirstName,LastName,companyName,ContryID,address,email,bphone,bfax,lID,memID,subject,mess,quantity,datepost,proOrder) values('".$cust_data["FirstName"]."','".$cust_data["LastName"]."','".$cust_data["CompanyName"]."',".$cust_data["countryID"].",'".$cust_data["Address"]."','".$cust_data["mEmail"]."','".$cust_data["bphone"]."','".$cust_data["bfax"]."',0,".$cust_data["memID"].",'$txtSubject','$txtMessage','$txtQuantity','".date("Y-m-d")."','3')";
 
		if(!$result=$db->sql_query($sql)){			 
	 		 message_die("Couldn't run the sql query!!!2","",__LINE__,__FILE__,$sql);
		}	
		 $filecontent='Dear '.$cust_data["FirstName"].',<br>
					You have a new message from a yellowpages.vn member. To view the message logon to the link below:<br>
					<a href="'.$site_base_href.'/userLog.php">'.$site_base_href.'</a><br><br>					
					Kind regards,<br>www.yellowpages.vn Team<br>';
					
		$mail= new email();	
		 
		$mail->to =$cust_data["mEmail"];
		$mail->toname =$cust_data["FirstName"];
		$mail->fromname ="VietBig";
		$mail->from = "support@yellowpages.vn";
		$mail->enable_html = true;				
		$mail->subject = "yellowpages.vn";
		$mail->body = $filecontent;		
		$mail->send();		
		echo ' <table width="100%"  border="0" cellspacing="0" cellpadding="0">
			<tr>
			<td height="300" valign="top" class="quote">	<div align="center" ><br>
			  <br>Thank you! Message Successfully Sent!<br>Thank you for contacting us. We will reply your inquiry as soon as possible.<br><br> </td>
			</tr>
			</table>
			'; 
		return;
	}
	
	$sql='select s.memID,s.lID,p.FirstName,p.LastName,m.mEmail,p.CompanyName,	p.Address,p.countryID,CONCAT(p.contrycode," ",p.areacode," ",BusinessPhone) as bphone,CONCAT(p.faxcontrycode," ",p.faxareacode," ",FaxNumber) as bfax  from vb_sell_lead s inner join vb_member m on m.memID=s.memID inner join vb_memberprofile p on m.memID=p.memID	where s.lID=-1';
	
	if(is_array($ses_pro)){
	
		while (list($id,) = each($ses_pro)){
			$id	= intval($id);
			if ($id){
				$sql.=" or s.lID=".$id;
			}
		}
 
		if(!$result=$db->sql_query($sql)){
			message_die("Couldn't run the sql query!!!3","",__LINE__,__FILE__,$sql);
		}	
		$cust_count=$db->sql_numrows($result);
		$cust_data=$db->sql_fetchrowset($result);	
		$db->sql_freeresult($result);	
		
		for($i=0;$i<$cust_count;$i++){
				$sql="insert into vb_contact(FirstName,LastName,companyName,ContryID,address,email,bphone,bfax,lID,memID,subject,mess,quantity,datepost,proOrder) values('".$cust_data[$i]["FirstName"]."','".$cust_data[$i]["LastName"]."','".$cust_data[$i]["CompanyName"]."',".$cust_data[$i]["countryID"].",'".$cust_data[$i]["Address"]."','".$cust_data[$i]["mEmail"]."','".$cust_data[$i]["bphone"]."','".$cust_data[$i]["bfax"]."',".$cust_data[$i]["lID"].",".$cust_data[$i]["memID"].",'$txtSubject','$txtMessage','$txtQuantity','".date("Y-m-d")."','0')";
	
			if(!$result=$db->sql_query($sql)){			 
				 message_die("Couldn't run the sql query!!!4","",__LINE__,__FILE__,$sql);
			}	
			 $filecontent='Dear '.$cust_data[$i]["FirstName"].',<br>
						You have a new message from a yellowpages.vn member. To view the message logon to the link below:<br>
						<a href="'.$site_base_href.'/userLog.php">'.$site_base_href.'</a><br><br>					
						Kind regards,<br>www.yellowpages.vn Team<br>';
			 
			$mail= new email();			 
			$mail->to =$cust_data[$i]["mEmail"];
			$mail->toname =$cust_data[$i]["FirstName"];
			$mail->fromname ="VietBig";
			$mail->from = "support@yellowpages.vn";
			$mail->enable_html = true;				
			$mail->subject = "yellowpages.vn";
			$mail->body = $filecontent;		
			$mail->send();		
		}
		$cust_data=array();
		unset($ses_pro);
		session_unregister("ses_pro");
		session_unregister("ses_pro1");
	}
	
  	if(is_array($ses_pros)){
		$sql='select s.memID,s.proID,p.FirstName,p.LastName,m.mEmail,p.CompanyName,	p.Address,p.countryID,CONCAT(p.contrycode," ",p.areacode," ",BusinessPhone) as bphone,CONCAT(p.faxcontrycode," ",p.faxareacode," ",FaxNumber) as bfax  from vb_products s inner join vb_member m on m.memID=s.memID inner join vb_memberprofile p on m.memID=p.memID where s.proID=-1';
		while (list($id,) = each($ses_pros)){
			$id	= intval($id);
			if ($id){
				$sql.=" or s.proID=".$id;
			}
		}
 
		if(!$result=$db->sql_query($sql)){
		  message_die("Couldn't run the sql query!!!5","",__LINE__,__FILE__,$sql);
		}	
		$cust_count=$db->sql_numrows($result);
		$cust_data=$db->sql_fetchrowset($result);	
		$db->sql_freeresult($result);	
	
		for($i=0;$i<$cust_count;$i++){
				$sql="insert into vb_contact(FirstName,LastName,companyName,ContryID,address,email,bphone,bfax,lID,memID,subject,mess,quantity,datepost,proOrder) values(
				'".$cust_data[$i]["FirstName"]."','".$cust_data[$i]["LastName"]."','".$cust_data[$i]["CompanyName"]."',".
				$cust_data[$i]["countryID"].",'".$cust_data[$i]["Address"]."','".$cust_data[$i]["mEmail"]."','".
				$cust_data[$i]["bphone"]."','".$cust_data[$i]["bfax"]."',".$cust_data[$i]["proID"].",".$cust_data[$i]["memID"].",'$txtSubject','$txtMessage','$txtQuantity','".date("Y-m-d")."','1')";
	 
			if(!$result=$db->sql_query($sql)){			 
				 message_die("Couldn't run the sql query!!!6","",__LINE__,__FILE__,$sql);
			}	
					 $filecontent='Dear '.$cust_data[$i]["FirstName"].',<br>
						You have a new message from a yellowpages.vn member. To view the message logon to the link below:<br>
						<a href="'.$site_base_href.'/userLog.php">'.$site_base_href.'</a><br><br>					
						Kind regards,<br>
						www.yellowpages.vn Team<br>';
						
			 
			$mail= new email();			 
			$mail->to =$cust_data[$i]["mEmail"];
			$mail->toname =$cust_data[$i]["FirstName"];
			$mail->fromname ="VietBig";
			$mail->from = "support@yellowpages.vn";
			$mail->enable_html = true;				
			$mail->subject = "yellowpages.vn";
			$mail->body = $filecontent;		
			$mail->send();	
		}
		$cust_data=array();
		unset($ses_pros);
		session_unregister("ses_pros");
		session_unregister("ses_pros1");
		}			
 
	echo ' <table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="300" valign="top" class="quote">	<div align="center" ><br>
      <br>Thank you! Message Successfully Sent!<br>Thank you for contacting us. We will reply your inquiry as soon as possible.<br><br><br><br><br><br><a href="javascript:window.close();" class="quote">Close</a>  </td>
  </tr>
</table>
';	
} 
function viewcontact(){
	global $template, $db, $template_products_body,$base_url,$site_base_href,$mode; 
	 
	$type=isset($_POST["type"]) ? htmlspecialchars($_POST["type"]) : ''; 
	$typev=isset($_GET["type"]) ? htmlspecialchars($_GET["type"]) : ''; 
	
	if($type=="addToCard" || $mode=="addToCard"){
		AddToBasket();
		return;
	}
	$ses_login=$_SESSION['ses_login'];
	if($ses_login["s_user"]){
		memContact();
		return;
	}else{
		guestContact();
		return;
	}	 
}
//============================================================================================================
function AddToBasket(){
	global $db,$template_contactList,$site_base_href,$base_url,$template,$ids;

	addCart();
	
	$ses_pro = isset($_SESSION["ses_pro"]) ? $_SESSION["ses_pro"] : '' ;
	$ses_pros= isset($_SESSION["ses_pros"]) ? $_SESSION["ses_pros"] : '' ;

	if(count($ses_pro)<1 && count($ses_pros)<1 ){
		redirect($site_base_href."/Inquiry.php?ids=".$ids."&lang=us");
	}
	
	if($ses_pro){
	$sql='select s.memID,s.lID,s.proID,s.subject,p.CompanyName,p.countryID from vb_sell_lead s inner join vb_member m on m.memID=s.memID inner join vb_memberprofile p on m.memID=p.memID
	where s.lID=-1';
	if(is_array($ses_pro)){
		while (list($id,) = each($ses_pro)){
			$id	= intval($id);
			if ($id){
				$sql.=" or s.lID=".$id;
			}
		}
	if(!$result=$db->sql_query($sql)){
	  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
	}	
	$cust_count=$db->sql_numrows($result);
	$cust_data=$db->sql_fetchrowset($result);	
	$db->sql_freeresult($result);	
	
	for($i=0;$i<$cust_count;$i++){
			$template->assign_block_vars("ContactList", array(							
				'subject' =>$cust_data[$i]["subject"],
				'url' => $site_base_href.'/supplier.php?supplier='.$cust_data[$i]["memID"].'&act=vleads&mode=leadsdetail&lid='.$cust_data[$i]["lID"],
				'company'	=>$cust_data[$i]["CompanyName"],
				'country' =>getContry($cust_data[$i]["countryID"]),				
				'CHECKBOX'	 => '<input type="Checkbox" name="proid['.$cust_data[$i]["lID"].']" value="'. $cust_data[$i]["proID"] .'" checked />'
			));
		}
	}
	}
	
	if($ses_pros){
	$sql='select s.memID,s.proID,s.ProductName,s.catID,p.CompanyName,p.countryID from vb_products s inner join vb_member m on m.memID=s.memID inner join vb_memberprofile p on m.memID=p.memID
	where s.proID=-1';
	if(is_array($ses_pros)){
	
		while (list($id,) = each($ses_pros)){
			$id	= intval($id);
			if ($id){
				$sql.=" or s.proID=".$id;
			}
		}
		 
	if(!$result=$db->sql_query($sql)){
	  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
	}	
	$cust_count=$db->sql_numrows($result);
	$cust_data=$db->sql_fetchrowset($result);	
	$db->sql_freeresult($result);	
	
	for($i=0;$i<$cust_count;$i++){
			$template->assign_block_vars("ContactList", array(							
				'subject' =>$cust_data[$i]["ProductName"],
				'url' => $site_base_href.'/supplier.php?ids='.$ids.'&lang=us&supplier='.$cust_data[$i]["memID"].'&act=products&mode=productDetail&pid='.$cust_data[$i]["proID"].'&catID='.$cust_data[$i]["catID"],
				'company'	=>$cust_data[$i]["CompanyName"],
				'country' =>getContry($cust_data[$i]["countryID"]),				
				'CHECKBOX'	 => '<input type="Checkbox" name="proidP['.$cust_data[$i]["proID"].']" value="1" checked />'
			));
		}
	}
	}
	$template->assign_vars(array(	
		'S_ACTION' =>$site_base_href.'/index.php?ids='.$ids.'&lang=us&/contact',
		'c_delete' =>$site_base_href.'/index.php?ids='.$ids.'&lang=us&/contact/delete'
	));
	
	$template->set_filenames(array(
		'body' =>$template_contactList
		));
	$template->pparse('body');		
}
function guestContact(){		
	global $template,$template_guestContact,$base_url,$site_base_href,$url,$ids;
	
	$supp =isset($_POST["suppli"]) ? intval($_POST["suppli"]) : 0;	
	if(!$supp){
	 	$supp = $url[2];
	}
	 addCart();
	 addCusCart();
	 getContry();
	$i=rand(4,5);
	for($j=0;$j<$i;$j++){
	 	$id_random .= chr(rand(65,90));
	}
 	$ses_pro=$_SESSION["ses_pro1"];
	$ses_pros=$_SESSION["ses_pros1"];
	
	if(is_array($ses_pro)){	
	 	$ses=count($ses_pro);
	}
	if(is_array($ses_pros)){	
	 	$ses+=count($ses_pros);
	}
	if($ses>1){
		$comp='<a href="javascript:void(0)" onClick="displayDiv()">'.$ses.' Company </a>';
	}else{
		$comp=getCompany();
	}
	$template->assign_vars(array(
		'company' =>$comp,
		'ranima' => base64_encode(base64_encode($id_random)),
		'hdranima' =>$id_random,
		'con_company' =>getCompany(),
		'getImage' =>$site_base_href.'/',
		'contactID' =>$supp,
		's_action'	=>$site_base_href."/".$base_url."?ids=".$ids."&lang=us&/contact/gsend/"		
	));
	
	$template->set_filenames(array(
		'body' =>$template_guestContact
	));
	$template->pparse('body');		
	 
}
function memContact(){
	global $template,$template_memContact,$site_base_href,$ses_pro,$ses_pros,$base_url,$url;
	
	addCart();
	addCusCart();
	$supp =isset($_POST["suppli"]) ? intval($_POST["suppli"]) : 0;	
	if(!$supp){
	 $supp = $url[2];
	}
	
	$ses_pro=$_SESSION["ses_pro1"];
	$ses_pros=$_SESSION["ses_pros1"]; 
	if(is_array($ses_pro)){	
	 $ses=count($ses_pro);
	}
	if(is_array($ses_pros)){	
	 $ses+=count($ses_pros);
	}
	 
	if($ses>1){
		$comp='<a href="javascript:void(0)" onClick="displayDiv()">'.$ses.' Company </a>';
	}else{
		$comp=getCompany();
	}
	$template->assign_vars(array(
		'company' =>$comp,
		'con_company' =>getCompany(),
		'contactID' =>$supp,
		's_action'	=>$site_base_href."/".$base_url."?ids=".$ids."&lang=us&/contact/send/"		
	));
	
	$template->set_filenames(array(
		'body' =>$template_memContact
	));
	$template->pparse('body');		
	unset($ses_pro);

}
function getCompany(){
	global $db,$ses_pro,$ses_pros,$url;
	
 	$ses_pro=$_SESSION["ses_pro1"];
	$ses_pros=$_SESSION["ses_pros1"];
	
	$supp =isset($_POST["suppli"]) ? intval($_POST["suppli"]) : 0;	
	if(!$supp){
	 $supp = $url[2];
	}
	$comName='';
 	
	if(!empty($supp)){
		$sup=$db->getRecord("select CompanyName from vb_memberprofile where memID=".$supp);
		$comName.=$sup."<br>";
	}
	 
	if($ses_pro){
	$sql='select  m.CompanyName,p.proID from vb_memberprofile m inner join vb_products p on m.memID=p.memID where p.proID=-1';
		while (list(, $id) = each($ses_pro)){
			$id	= intval($id);
			if ($id){
				$sql.=" or p.proID=".$id;
			}
		}
 	 
	if(!$result=$db->sql_query($sql)){
	  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
	}
	$comp=array();
	$cust_count=$db->sql_numrows($result);
	$cust_data=$db->sql_fetchrowset($result);	
	$db->sql_freeresult($result);	
	for($i=0;$i<$cust_count;$i++){
		$comp[$cust_data[$i]["proID"]]=$cust_data[$i]["CompanyName"];
	}
	$cust_data=array();
	 	$ses_pro=$_SESSION["ses_pro1"];
		while (list(,$id) = each($ses_pro)){
			$id	= intval($id);			 
			if ($id){
				$comName.=$comp[$id]."<br>";
			}
	 }
	}	 
	 
	if($ses_pros){
	
		$sql='select  m.CompanyName,p.proID from vb_memberprofile m inner join vb_products p on m.memID=p.memID where p.proID=-1';
		while (list($id,) = each($ses_pros)){
			$id	= intval($id);
			if ($id){
				$sql.=" or p.proID=".$id;
			}
		}
		 
		 
		if(!$result=$db->sql_query($sql)){
		  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
		}
		$comp=array();
		$cust_count=$db->sql_numrows($result);
		$cust_data=$db->sql_fetchrowset($result);	
		$db->sql_freeresult($result);	
		 
		for($i=0;$i<$cust_count;$i++){
			$comp[$cust_data[$i]["proID"]]=$cust_data[$i]["CompanyName"];
		}
		$cust_data=array();
		 $ses_pros=$_SESSION["ses_pros1"];				 
			while (list($id,$value) = each($ses_pros)){			
				$id	= intval($id);			 
				if ($id){
					$comName.=$comp[$id]."<br>";
					
					 
				}
		}
		}
	return $comName;

}
function addCart(){	
	$proid	= isset($_POST["proid"]) ? $_POST["proid"] : '';
	
	if ( !empty($proid) ){
		if ( !is_array($proid) ){
			$pro_id[0]	= $proid;
		}else{
			$pro_id	= $proid;
		}
		unset($proid);
		
		if(!$HTTP_SESSION_VARS["ses_pro"]){
			session_register("ses_pro");		
		}	
		$ses_pro=$_SESSION["ses_pro"];
		if(count($ses_pro)>38){
			return;
		}
		while (list($id, $value) = each($pro_id)){
			$id	= intval($id);
			if ($id){
				$ses_pro[$id]=$value;					 
			}
		}	
		
		$_SESSION['ses_pro']=$ses_pro;	
	}
	
	return;
}
function deleteContact(){	
	 global $site_base_href;
	$proid	= isset($_POST["proid"]) ? $_POST["proid"] : '';
	$proidP	= isset($_POST["proidP"]) ? $_POST["proidP"] : '';
	$ses_pro=$_SESSION["ses_pro"];		
	
	if ( !empty($proid) ){
		if ( !is_array($proid) ){
			$pro_id[0]	= $proid;
		}
		else{
			$pro_id	= $proid;
		}
		unset($proid);	
		
		while (list($id, $value) = each($pro_id)){
			$id	= intval($id);
			if ($value){
				unset($ses_pro[$id]);			
				
			}
		}		
		$_SESSION['ses_pro']=$ses_pro;		
	}
 
	if (!empty($proidP) ){
	
		$ses_pros=$_SESSION["ses_pros"];		
		
		if ( !is_array($proidP) ){
			$pro_id[1]	= $proidP;
		}
		else{
			$pro_id	= $proidP;
		}
		unset($proidP);	
		
		while (list($id, $value) = each($pro_id)){
			$id	= intval($id);
			if ($value){
				unset($ses_pros[$id]);			
				
			}
		}		
		$_SESSION['ses_pros']=$ses_pros;		
	}
	
	redirect($site_base_href."/index.php?/contact/addToCard");
}
function addCusCart(){	
	$productsid	= isset($_POST["proidP"]) ? $_POST["proidP"] : '';
	$proid	= isset($_POST["proid"]) ? $_POST["proid"] : '';	
	
	$_SESSION["ses_pro1"]='';
	$_SESSION["ses_pros1"]='';
	
	 //selling lead
	if ( !empty($proid) ){
	
		if ( !is_array($proid) ){
			$pro_id[0]	= $proid;
		}
		else{
			$pro_id	= $proid;
		}
		unset($proid);
		
		if(!$HTTP_SESSION_VARS["ses_pro1"]){
			session_register("ses_pro1");		
		}	
		while (list($id, $value) = each($pro_id)){
			$id	= intval($id);
			if ($id){
				$ses_pro[$id]=$value;					 
			}
		}	
		$_SESSION['ses_pro1']=$ses_pro;	
	}
	$pro_id='';
	$ses_pros='';
	//products
	if ( !empty($productsid) ){
		if ( !is_array($productsid) ){
			$pro_id[0]	= $productsid;
		}
		else{
			$pro_id	= $productsid;
		}
		unset($productsid);
		
		if(!$HTTP_SESSION_VARS["ses_pros1"]){
			session_register("ses_pros1");		
		}	
		while (list($id, $value) = each($pro_id)){
			$id	= intval($id);
			if ($id){
				$ses_pros[$id]=$value;					 
			}
		}	
		$_SESSION['ses_pros1']=$ses_pros;	
	} 
	return;
}
?>